import req, { cancelableReq } from '@/utils/request.js';
import * as URL from '@/constants/api.js';

export function login(params) {
  // 返回Promise
  // 返回取消函数
  return cancelableReq({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  });
  // .then((res) => {
  //   localStorage.setItem('TOKEN', res.data.result.token);
  //   return res.data;
  // })
  // .catch((err) => Promise.reject(err.response.data));
}

export function loginWithCode(mobile) {
  return req({
    url: URL.LOGIN_CODE,
    params: {
      mobile,
    },
  })
    .then((res) => res.data.msg)
    .catch((err) => Promise.reject(err.response.data.message));
}
